package com.npjscg.medicalpro.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.npjscg.medicalpro.controller.dto.FormDTO;
import com.npjscg.medicalpro.controller.dto.ReportDTO;
import com.npjscg.medicalpro.entity.Report;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author raote
 * @since 2022-06-29
 */
public interface ReportMapper extends BaseMapper<Report> {



    @Select("SELECT * FROM t_report JOIN (t_check LEFT JOIN sys_user ON t_check.adminid = sys_user.id) ON t_report.id = t_check.rid WHERE status = #{status} AND uid = #{uid} AND temname LIKE #{temname}")
    Page<ReportDTO> getByStatus(@Param("page") Page<ReportDTO> page, int uid, int status, String temname);

    @Select("SELECT * FROM (t_report LEFT JOIN t_dep ON t_report.did = t_dep.id)LEFT JOIN t_template ON t_report.tid = t_template.id WHERE t_report.id = #{id}")
    FormDTO getDTO(Integer id);

    @Insert("insert into t_report(tid,uid,temname,did,hcode,address,doctornum,repr,categ,pro,eco) values (#{tid},#{uid},#{temname},#{did},#{hcode},#{address},#{doctornum},#{repr},#{categ},#{pro},#{eco})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void saveReport(Report report);
}
